package demo2;
//电脑类
public class Computer {
    public void powerOn() {
        System.out.println("打开电脑");
    }
    public void poweroff() {
        System.out.println("关闭电脑");
    }
    //通过电脑来操作USB接口
    public void useDevice(IUSB iusb) {
        iusb.openDevice();//打开设备
        //判断接口的类型
        if(iusb instanceof Mouse) {
           Mouse mouse = (Mouse)iusb;//向下转型
            mouse.click();//只有Mouse里面才有click方法
        } else if(iusb instanceof KeyBorad) {
            KeyBorad keyborad = (KeyBorad)iusb;
            keyborad.inPut();
        }
        iusb.colseDevice();//关设备
    }
}
